@@ -1,91 +0,0 @@ |
||
| 1 |
-package ai.pai.lensman.main; |
|
| 2 |
- |
|
| 3 |
-import android.os.AsyncTask; |
|
| 4 |
- |
|
| 5 |
-import com.android.common.executors.ThreadExecutor; |
|
| 6 |
- |
|
| 7 |
-import org.json.JSONArray; |
|
| 8 |
-import org.json.JSONObject; |
|
| 9 |
- |
|
| 10 |
-import java.util.ArrayList; |
|
| 11 |
-import java.util.HashMap; |
|
| 12 |
- |
|
| 13 |
-import ai.pai.lensman.base.BaseInteractor; |
|
| 14 |
-import ai.pai.lensman.utils.HttpPostTask; |
|
| 15 |
-import ai.pai.lensman.utils.UrlContainer; |
|
| 16 |
- |
|
| 17 |
-/** |
|
| 18 |
- * Created by chengzhenyu on 2016/8/14. |
|
| 19 |
- */ |
|
| 20 |
-public class FetchSessionIdsInteractor implements BaseInteractor {
|
|
| 21 |
- |
|
| 22 |
- private HttpPostTask fetchSessionIdsTask; |
|
| 23 |
- private String lensmanId; |
|
| 24 |
- private int num; |
|
| 25 |
- private InteractorListener<ArrayList<String>> listener; |
|
| 26 |
- |
|
| 27 |
- public FetchSessionIdsInteractor(String lensmanId, int num, InteractorListener<ArrayList<String>> listener){
|
|
| 28 |
- this.num = num; |
|
| 29 |
- this.listener = listener; |
|
| 30 |
- this.lensmanId = lensmanId; |
|
| 31 |
- } |
|
| 32 |
- |
|
| 33 |
- @Override |
|
| 34 |
- public void startJob() {
|
|
| 35 |
- cancelJob(); |
|
| 36 |
- HashMap<String,String> params = new HashMap<>(); |
|
| 37 |
- params.put("user_id",lensmanId);
|
|
| 38 |
- params.put("num",String.valueOf(num));
|
|
| 39 |
- fetchSessionIdsTask = new HttpPostTask(params){
|
|
| 40 |
- |
|
| 41 |
- String message; |
|
| 42 |
- ArrayList<String> sessionIds; |
|
| 43 |
- @Override |
|
| 44 |
- protected boolean parseResponse(String response) {
|
|
| 45 |
- try{
|
|
| 46 |
- JSONObject json = new JSONObject(response); |
|
| 47 |
- int status = json.getInt("status");
|
|
| 48 |
- if(status == 200){
|
|
| 49 |
- JSONArray sessionArray = json.getJSONArray("data");
|
|
| 50 |
- if(sessionArray!=null && sessionArray.length()>0){
|
|
| 51 |
- sessionIds = new ArrayList<>(); |
|
| 52 |
- for(int k = 0; k< sessionArray.length();k++){
|
|
| 53 |
- sessionIds.add(sessionArray.getString(k)); |
|
| 54 |
- } |
|
| 55 |
- } |
|
| 56 |
- return true; |
|
| 57 |
- }else{
|
|
| 58 |
- message = json.getString("message");
|
|
| 59 |
- } |
|
| 60 |
- }catch (Exception e){
|
|
| 61 |
- e.printStackTrace(); |
|
| 62 |
- } |
|
| 63 |
- return false; |
|
| 64 |
- } |
|
| 65 |
- |
|
| 66 |
- @Override |
|
| 67 |
- protected void onPostFail() {
|
|
| 68 |
- super.onPostFail(); |
|
| 69 |
- listener.onInteractFail(message); |
|
| 70 |
- } |
|
| 71 |
- |
|
| 72 |
- @Override |
|
| 73 |
- protected void onPostSuccess() {
|
|
| 74 |
- super.onPostSuccess(); |
|
| 75 |
- listener.onInteractSuccess(sessionIds); |
|
| 76 |
- } |
|
| 77 |
- }; |
|
| 78 |
- fetchSessionIdsTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.SESSION_IDS_CREATE); |
|
| 79 |
- } |
|
| 80 |
- |
|
| 81 |
- @Override |
|
| 82 |
- public void cancelJob() {
|
|
| 83 |
- if(fetchSessionIdsTask==null){
|
|
| 84 |
- return; |
|
| 85 |
- } |
|
| 86 |
- if(fetchSessionIdsTask.getStatus()== AsyncTask.Status.RUNNING){
|
|
| 87 |
- fetchSessionIdsTask.cancel(true); |
|
| 88 |
- } |
|
| 89 |
- fetchSessionIdsTask = null; |
|
| 90 |
- } |
|
| 91 |
-} |
@@ -7,7 +7,6 @@ import android.os.Binder; |
||
| 7 | 7 |
import android.os.Handler; |
| 8 | 8 |
import android.os.IBinder; |
| 9 | 9 |
import android.os.Message; |
| 10 |
-import android.text.TextUtils; |
|
| 11 | 10 |
|
| 12 | 11 |
import com.android.common.executors.ThreadExecutor; |
| 13 | 12 |
import com.android.common.utils.LogHelper; |
@@ -16,18 +15,11 @@ import org.json.JSONArray; |
||
| 16 | 15 |
import org.json.JSONObject; |
| 17 | 16 |
|
| 18 | 17 |
import java.io.File; |
| 19 |
-import java.io.FileOutputStream; |
|
| 20 |
-import java.io.InputStream; |
|
| 21 |
-import java.net.HttpURLConnection; |
|
| 22 |
-import java.net.URL; |
|
| 23 | 18 |
import java.util.ArrayList; |
| 24 | 19 |
import java.util.HashMap; |
| 25 | 20 |
|
| 26 |
-import ai.pai.lensman.BuildConfig; |
|
| 27 | 21 |
import ai.pai.lensman.bean.OrderBean; |
| 28 |
-import ai.pai.lensman.bean.PhotoBean; |
|
| 29 | 22 |
import ai.pai.lensman.db.Preferences; |
| 30 |
-import ai.pai.lensman.utils.BoxUrlContainer; |
|
| 31 | 23 |
import ai.pai.lensman.utils.Constants; |
| 32 | 24 |
import ai.pai.lensman.utils.HttpPostTask; |
| 33 | 25 |
import ai.pai.lensman.utils.UrlContainer; |
@@ -77,7 +69,7 @@ public class OrderDealService extends Service implements Handler.Callback{
|
||
| 77 | 69 |
JSONObject data = json.getJSONObject("data");
|
| 78 | 70 |
JSONArray orders = data.getJSONArray("wanted");
|
| 79 | 71 |
if (orders != null && orders.length() > 0) {
|
| 80 |
- orderList = new ArrayList<OrderBean>(); |
|
| 72 |
+ orderList = new ArrayList<>(); |
|
| 81 | 73 |
for (int k = 0; k < orders.length(); k++) {
|
| 82 | 74 |
JSONObject orderObj = orders.getJSONObject(k); |
| 83 | 75 |
OrderBean bean = new OrderBean(); |
@@ -128,7 +120,7 @@ public class OrderDealService extends Service implements Handler.Callback{
|
||
| 128 | 120 |
if (!isQueueEmpty()) {
|
| 129 | 121 |
OrderBean orderBean = orderList.get(0); |
| 130 | 122 |
LogHelper.d(TAG,"当前有未处理的订单" +orderBean); |
| 131 |
- fetchOriginFromBox(orderBean); |
|
| 123 |
+ uploadOrigin(orderBean); |
|
| 132 | 124 |
} else {
|
| 133 | 125 |
LogHelper.d(TAG,"当前没有订单,10s后再次查询"); |
| 134 | 126 |
handler.removeMessages(MSG_QUERY_ORDER); |
@@ -136,79 +128,6 @@ public class OrderDealService extends Service implements Handler.Callback{
|
||
| 136 | 128 |
} |
| 137 | 129 |
} |
| 138 | 130 |
|
| 139 |
- private void fetchOriginFromBox(final OrderBean orderBean) {
|
|
| 140 |
- LogHelper.d(TAG, "fetchOriginFromBox 从box中获取原图 "+orderBean); |
|
| 141 |
- HashMap<String, String> params = new HashMap<>(); |
|
| 142 |
- params.put("lensman", Preferences.getInstance().getLensManId());
|
|
| 143 |
- params.put("session", orderBean.sessionId);
|
|
| 144 |
- params.put("id", orderBean.photoId);
|
|
| 145 |
- |
|
| 146 |
- //TODO for test |
|
| 147 |
- if(BuildConfig.isTestMode){
|
|
| 148 |
- PhotoBean bean = new PhotoBean(); |
|
| 149 |
- bean.photoId = Long.parseLong(orderBean.photoId); |
|
| 150 |
- bean.photoName = bean.photoId+".jpg"; |
|
| 151 |
- bean.photoPath = "http://img.pconline.com.cn/images/upload/upc/tx/wallpaper/1402/12/c1/31189058_1392186616852.jpg"; |
|
| 152 |
- bean.captureTime = bean.photoId; |
|
| 153 |
- bean.isRawPhoto = false; |
|
| 154 |
- bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN; |
|
| 155 |
- bean.sessionId = orderBean.sessionId; |
|
| 156 |
- bean.lensmanId = Preferences.getInstance().getLensManId(); |
|
| 157 |
- orderBean.photoBean = bean; |
|
| 158 |
- new SavePhotoTask(orderBean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), orderBean); |
|
| 159 |
- return; |
|
| 160 |
- } |
|
| 161 |
- new HttpPostTask(params) {
|
|
| 162 |
- |
|
| 163 |
- @Override |
|
| 164 |
- protected boolean parseResponse(String response) {
|
|
| 165 |
- LogHelper.d(TAG, "fetchOriginFromBox get response string = " + response); |
|
| 166 |
- try {
|
|
| 167 |
- JSONObject json = new JSONObject(response); |
|
| 168 |
- int status = json.getInt("status");
|
|
| 169 |
- if (status == 200) {
|
|
| 170 |
- JSONObject data = json.getJSONObject("data");
|
|
| 171 |
- PhotoBean bean = new PhotoBean(); |
|
| 172 |
- bean.photoId = Long.parseLong(orderBean.photoId); |
|
| 173 |
- bean.photoName = bean.photoId+".jpg"; |
|
| 174 |
- bean.photoPath = data.getString("path");
|
|
| 175 |
- bean.captureTime = bean.photoId; |
|
| 176 |
- bean.isRawPhoto = false; |
|
| 177 |
- bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN; |
|
| 178 |
- bean.sessionId = orderBean.sessionId; |
|
| 179 |
- bean.lensmanId = Preferences.getInstance().getLensManId(); |
|
| 180 |
- orderBean.photoBean = bean; |
|
| 181 |
- } |
|
| 182 |
- return true; |
|
| 183 |
- } catch (Exception e) {
|
|
| 184 |
- e.printStackTrace(); |
|
| 185 |
- } |
|
| 186 |
- return false; |
|
| 187 |
- } |
|
| 188 |
- |
|
| 189 |
- @Override |
|
| 190 |
- protected void onPostFail() {
|
|
| 191 |
- super.onPostFail(); |
|
| 192 |
- LogHelper.d(TAG,"fetchOriginFromBox onPostFail 获取原图失败"); |
|
| 193 |
- orderList.remove(orderBean); |
|
| 194 |
- dealOrder(); |
|
| 195 |
- } |
|
| 196 |
- |
|
| 197 |
- @Override |
|
| 198 |
- protected void onPostSuccess() {
|
|
| 199 |
- super.onPostSuccess(); |
|
| 200 |
- if(TextUtils.isEmpty(orderBean.photoBean.photoPath)){
|
|
| 201 |
- LogHelper.d(TAG,"fetchOriginFromBox onPostSuccess 获取原图失败,因为原图已被删除"); |
|
| 202 |
- reportOriginPhotoDeleted(orderBean); |
|
| 203 |
- }else{
|
|
| 204 |
- LogHelper.d(TAG,"fetchOriginFromBox onPostSuccess 获取原图地址成功,准备保存"); |
|
| 205 |
- new SavePhotoTask(orderBean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), orderBean); |
|
| 206 |
- } |
|
| 207 |
- } |
|
| 208 |
- }.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.FETCH_ORIGIN_URL); |
|
| 209 |
- |
|
| 210 |
- } |
|
| 211 |
- |
|
| 212 | 131 |
private void uploadOrigin(OrderBean bean) {
|
| 213 | 132 |
new UploadTask(bean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor()); |
| 214 | 133 |
} |
@@ -234,115 +153,6 @@ public class OrderDealService extends Service implements Handler.Callback{
|
||
| 234 | 153 |
|
| 235 | 154 |
} |
| 236 | 155 |
|
| 237 |
- class SavePhotoTask extends AsyncTask<OrderBean, Integer, Boolean> {
|
|
| 238 |
- |
|
| 239 |
- private OrderBean orderBean; |
|
| 240 |
- |
|
| 241 |
- public SavePhotoTask(OrderBean bean) {
|
|
| 242 |
- this.orderBean = bean; |
|
| 243 |
- } |
|
| 244 |
- |
|
| 245 |
- @Override |
|
| 246 |
- protected Boolean doInBackground(OrderBean... params) {
|
|
| 247 |
- |
|
| 248 |
- String path = BoxUrlContainer.PHOTO_PATH_PREFIX_URL + orderBean.photoBean.photoPath; |
|
| 249 |
- if(BuildConfig.isTestMode){
|
|
| 250 |
- path = "http://img.pconline.com.cn/images/upload/upc/tx/wallpaper/1402/12/c1/31189058_1392186616852.jpg"; |
|
| 251 |
- } |
|
| 252 |
- LogHelper.d(TAG, "SavePhotoTask 保存照片到本地,图片链接地址为" + path); |
|
| 253 |
- FileOutputStream fOut = null; |
|
| 254 |
- HttpURLConnection conn = null; |
|
| 255 |
- InputStream inStream = null; |
|
| 256 |
- try {
|
|
| 257 |
- URL url = new URL(path); |
|
| 258 |
- conn = (HttpURLConnection) url.openConnection(); |
|
| 259 |
- conn.setConnectTimeout(5 * 1000); |
|
| 260 |
- conn.setRequestMethod("GET");
|
|
| 261 |
- inStream = conn.getInputStream(); |
|
| 262 |
- if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
|
| 263 |
- String dirPath = ai.pai.lensman.utils.Constants.APP_IMAGE_DIR + File.separator + orderBean.photoBean.sessionId + File.separator + Constants.ORIGIN_DIR_NAME; |
|
| 264 |
- File dir = new File(dirPath); |
|
| 265 |
- dir.mkdirs(); |
|
| 266 |
- File file = new File(dir, orderBean.photoBean.photoName); |
|
| 267 |
- fOut = new FileOutputStream(file); |
|
| 268 |
- byte[] buffer = new byte[2048]; |
|
| 269 |
- int len; |
|
| 270 |
- while ((len = inStream.read(buffer)) != -1) {
|
|
| 271 |
- fOut.write(buffer, 0, len); |
|
| 272 |
- fOut.flush(); |
|
| 273 |
- } |
|
| 274 |
- fOut.flush(); |
|
| 275 |
- LogHelper.d(TAG, "SavePhotoTask 保存照片到本地,图片保存至" + file.getAbsolutePath() + "图片大小为" + file.length() + "字节\n\n"); |
|
| 276 |
- } |
|
| 277 |
- return true; |
|
| 278 |
- } catch (Exception e) {
|
|
| 279 |
- e.printStackTrace(); |
|
| 280 |
- } finally {
|
|
| 281 |
- try {
|
|
| 282 |
- inStream.close(); |
|
| 283 |
- conn.disconnect(); |
|
| 284 |
- fOut.close(); |
|
| 285 |
- } catch (Exception e) {
|
|
| 286 |
- e.printStackTrace(); |
|
| 287 |
- } |
|
| 288 |
- } |
|
| 289 |
- return false; |
|
| 290 |
- } |
|
| 291 |
- |
|
| 292 |
- @Override |
|
| 293 |
- protected void onPostExecute(Boolean result) {
|
|
| 294 |
- super.onPostExecute(result); |
|
| 295 |
- if (result) {
|
|
| 296 |
- LogHelper.d(TAG,"savePhotoTask onPostExecute success 保存本地成功,准备上传"); |
|
| 297 |
- uploadOrigin(orderBean); |
|
| 298 |
- } else {
|
|
| 299 |
- LogHelper.d(TAG,"savePhotoTask onPostExecute fail 保存本地失败,下次重试"); |
|
| 300 |
- orderList.remove(orderBean); |
|
| 301 |
- dealOrder(); |
|
| 302 |
- } |
|
| 303 |
- } |
|
| 304 |
- } |
|
| 305 |
- private void reportOriginPhotoDeleted(final OrderBean orderBean) {
|
|
| 306 |
- HashMap<String, String> params = new HashMap<>(); |
|
| 307 |
- params.put("user_id", Preferences.getInstance().getLensManId());
|
|
| 308 |
- params.put("session_id", orderBean.sessionId);
|
|
| 309 |
- params.put("order_id", orderBean.orderId);
|
|
| 310 |
- params.put("photo_id", orderBean.photoId);
|
|
| 311 |
- params.put("deleted", String.valueOf(1));
|
|
| 312 |
- new HttpPostTask(params) {
|
|
| 313 |
- |
|
| 314 |
- @Override |
|
| 315 |
- protected boolean parseResponse(String response) {
|
|
| 316 |
- LogHelper.d(TAG, "reportOriginPhotoDeleted get response string = " + response); |
|
| 317 |
- try {
|
|
| 318 |
- JSONObject json = new JSONObject(response); |
|
| 319 |
- int status = json.getInt("status");
|
|
| 320 |
- if (status == 200) {
|
|
| 321 |
- return true; |
|
| 322 |
- } |
|
| 323 |
- } catch (Exception e) {
|
|
| 324 |
- e.printStackTrace(); |
|
| 325 |
- } |
|
| 326 |
- return false; |
|
| 327 |
- } |
|
| 328 |
- |
|
| 329 |
- @Override |
|
| 330 |
- protected void onPostFail() {
|
|
| 331 |
- super.onPostFail(); |
|
| 332 |
- orderList.remove(orderBean); |
|
| 333 |
- dealOrder(); |
|
| 334 |
- } |
|
| 335 |
- |
|
| 336 |
- @Override |
|
| 337 |
- protected void onPostSuccess() {
|
|
| 338 |
- super.onPostSuccess(); |
|
| 339 |
- orderList.remove(orderBean); |
|
| 340 |
- dealOrder(); |
|
| 341 |
- } |
|
| 342 |
- }.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.ORIGIN_PHOTO_UPLOAD_URL); |
|
| 343 |
- |
|
| 344 |
- LogHelper.d(TAG,"reportOriginPhotoDeleted task executes 上报服务器原图已删除"); |
|
| 345 |
- } |
|
| 346 | 156 |
public class UploadTask extends AsyncTask<Void, Integer, Boolean> {
|
| 347 | 157 |
|
| 348 | 158 |
private OrderBean bean; |
@@ -1,21 +1,8 @@ |
||
| 1 | 1 |
package ai.pai.lensman.session; |
| 2 | 2 |
|
| 3 |
-import android.os.AsyncTask; |
|
| 4 |
- |
|
| 5 |
-import com.android.common.executors.ThreadExecutor; |
|
| 6 | 3 |
import com.android.common.utils.LogHelper; |
| 7 | 4 |
|
| 8 |
-import org.json.JSONArray; |
|
| 9 |
-import org.json.JSONObject; |
|
| 10 |
- |
|
| 11 |
-import java.io.File; |
|
| 12 |
-import java.io.FileOutputStream; |
|
| 13 |
-import java.io.InputStream; |
|
| 14 |
-import java.net.HttpURLConnection; |
|
| 15 |
-import java.net.URL; |
|
| 16 | 5 |
import java.util.ArrayList; |
| 17 |
-import java.util.HashMap; |
|
| 18 |
-import java.util.Random; |
|
| 19 | 6 |
import java.util.Timer; |
| 20 | 7 |
import java.util.TimerTask; |
| 21 | 8 |
|
@@ -23,18 +10,13 @@ import ai.pai.lensman.BuildConfig; |
||
| 23 | 10 |
import ai.pai.lensman.bean.PhotoBean; |
| 24 | 11 |
import ai.pai.lensman.bean.SessionBean; |
| 25 | 12 |
import ai.pai.lensman.db.DBService; |
| 26 |
-import ai.pai.lensman.utils.BoxUrlContainer; |
|
| 27 |
-import ai.pai.lensman.utils.Constants; |
|
| 28 |
-import ai.pai.lensman.utils.HttpPostTask; |
|
| 29 | 13 |
|
| 30 | 14 |
public class SessionInteractor {
|
| 31 | 15 |
|
| 32 | 16 |
private SessionBean sessionBean; |
| 33 | 17 |
private Timer timer; |
| 34 | 18 |
private SessionListener listener; |
| 35 |
- private HttpPostTask sessionStartTask; |
|
| 36 |
- private HttpPostTask sessionEndTask; |
|
| 37 |
- private String randomSessionId; |
|
| 19 |
+ |
|
| 38 | 20 |
private long maxId = 0; |
| 39 | 21 |
private boolean isWorking; |
| 40 | 22 |
private boolean isLastQueryReturned = true; |
@@ -55,13 +37,7 @@ public class SessionInteractor {
|
||
| 55 | 37 |
|
| 56 | 38 |
public void startSession(){
|
| 57 | 39 |
LogHelper.d(TAG,"startSession"); |
| 58 |
- if(BuildConfig.isTestMode){
|
|
| 59 |
- isWorking = true; |
|
| 60 |
- listener.onSessionStartSuccess(sessionBean.sessionId); |
|
| 61 |
- startCapture(); |
|
| 62 |
- return; |
|
| 63 |
- } |
|
| 64 |
- cancelTask(sessionStartTask); |
|
| 40 |
+ |
|
| 65 | 41 |
ArrayList<PhotoBean> photoList = DBService.getInstance().getPhotoListBySessionId(sessionBean.sessionId); |
| 66 | 42 |
if(photoList!=null && photoList.size()>0){
|
| 67 | 43 |
for(PhotoBean photoBean : photoList){
|
@@ -70,47 +46,11 @@ public class SessionInteractor {
|
||
| 70 | 46 |
} |
| 71 | 47 |
} |
| 72 | 48 |
} |
| 73 |
- HashMap<String,String> params = new HashMap<>(); |
|
| 74 |
- params.put("lensman",sessionBean.lensmanId);
|
|
| 75 |
- randomSessionId = sessionBean.lensmanId+"_"+sessionBean.createTime+"_"+(new Random().nextInt(9999)+10000); |
|
| 76 |
- params.put("session",randomSessionId);
|
|
| 77 |
- sessionStartTask = new HttpPostTask(params){
|
|
| 78 |
- @Override |
|
| 79 |
- protected boolean parseResponse(String response) {
|
|
| 80 |
- LogHelper.d(TAG,"startSession get response string = "+response); |
|
| 81 |
- try{
|
|
| 82 |
- JSONObject json = new JSONObject(response); |
|
| 83 |
- int status = json.getInt("status");
|
|
| 84 |
- if(status == 200){
|
|
| 85 |
- return true; |
|
| 86 |
- } |
|
| 87 |
- }catch (Exception e){
|
|
| 88 |
- e.printStackTrace(); |
|
| 89 |
- } |
|
| 90 |
- return false; |
|
| 91 |
- } |
|
| 92 | 49 |
|
| 93 |
- @Override |
|
| 94 |
- protected void onPostFail() {
|
|
| 95 |
- LogHelper.d(TAG,"sessionStartTask onPostFail sessionId = "+randomSessionId); |
|
| 96 |
- super.onPostFail(); |
|
| 97 |
- listener.onSessionStartError(sessionBean.sessionId); |
|
| 98 |
- //即使session创建不成功,也继续工作,照片存lost目录 |
|
| 99 |
- isWorking = true; |
|
| 100 |
- LogHelper.d(TAG,"即使session创建不成功,也继续工作,照片存lost目录 sessionStartTask onPostSuccess sessionId = "+randomSessionId + "and startCapture"); |
|
| 101 |
- startCapture(); |
|
| 102 |
- } |
|
| 50 |
+ listener.onSessionStartSuccess(sessionBean.sessionId); |
|
| 51 |
+ isWorking = true; |
|
| 52 |
+ startCapture(); |
|
| 103 | 53 |
|
| 104 |
- @Override |
|
| 105 |
- protected void onPostSuccess() {
|
|
| 106 |
- super.onPostSuccess(); |
|
| 107 |
- listener.onSessionStartSuccess(sessionBean.sessionId); |
|
| 108 |
- isWorking = true; |
|
| 109 |
- LogHelper.d(TAG,"sessionStartTask onPostSuccess sessionId = "+randomSessionId + "and startCapture"); |
|
| 110 |
- startCapture(); |
|
| 111 |
- } |
|
| 112 |
- }; |
|
| 113 |
- sessionStartTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_START_URL); |
|
| 114 | 54 |
LogHelper.d(TAG,"startSession sessionStartTask execute"); |
| 115 | 55 |
} |
| 116 | 56 |
|
@@ -123,12 +63,12 @@ public class SessionInteractor {
|
||
| 123 | 63 |
timer.schedule(new TimerTask() {
|
| 124 | 64 |
@Override |
| 125 | 65 |
public void run() {
|
| 126 |
- fetchThumbnailTask(); |
|
| 66 |
+ fetchPhotoTask(); |
|
| 127 | 67 |
} |
| 128 | 68 |
},5000,2000); |
| 129 | 69 |
} |
| 130 | 70 |
|
| 131 |
- private void fetchThumbnailTask(){
|
|
| 71 |
+ private void fetchPhotoTask(){
|
|
| 132 | 72 |
if(!isWorking){
|
| 133 | 73 |
return; |
| 134 | 74 |
} |
@@ -160,149 +100,15 @@ public class SessionInteractor {
|
||
| 160 | 100 |
bean.sessionSeq = sessionBean.sessionSeq; |
| 161 | 101 |
bean.sessionDate = sessionBean.sessionDate; |
| 162 | 102 |
bean.sessionCreateTime = sessionBean.createTime; |
| 163 |
- new SavePhotoTask(bean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),bean); |
|
| 103 |
+ //TODO |
|
| 164 | 104 |
return; |
| 165 | 105 |
} |
| 166 |
- HashMap<String,String> params = new HashMap<>(); |
|
| 167 |
- params.put("lensman",sessionBean.lensmanId);
|
|
| 168 |
- params.put("session",randomSessionId);
|
|
| 169 |
- params.put("maxid",String.valueOf(maxId));
|
|
| 170 |
- HttpPostTask fetchThumbnailTask = new HttpPostTask(params){
|
|
| 171 |
- ArrayList<PhotoBean> photoList = new ArrayList<>(); |
|
| 172 |
- @Override |
|
| 173 |
- protected boolean parseResponse(String response) {
|
|
| 174 |
- LogHelper.d(TAG,"fetchThumbnailTask get response string = "+response); |
|
| 175 |
- try{
|
|
| 176 |
- JSONObject json = new JSONObject(response); |
|
| 177 |
- int status = json.getInt("status");
|
|
| 178 |
- if(status == 200){
|
|
| 179 |
- JSONObject data = json.getJSONObject("data");
|
|
| 180 |
- JSONArray files = data.getJSONArray("files");
|
|
| 181 |
- if(files!=null && files.length()>0){
|
|
| 182 |
- for(int k = 0 ; k< files.length();k++){
|
|
| 183 |
- JSONObject file = files.getJSONObject(k); |
|
| 184 |
- PhotoBean bean = new PhotoBean(); |
|
| 185 |
- bean.photoName = file.getString("name");
|
|
| 186 |
- bean.photoId = file.getLong("id");
|
|
| 187 |
- bean.photoPath = file.getString("path");
|
|
| 188 |
- bean.captureTime = bean.photoId; |
|
| 189 |
- bean.isRawPhoto = false; |
|
| 190 |
- bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN; |
|
| 191 |
- bean.sessionId = sessionBean.sessionId; |
|
| 192 |
- bean.lensmanId = sessionBean.lensmanId; |
|
| 193 |
- bean.sessionSeq = sessionBean.sessionSeq; |
|
| 194 |
- bean.sessionDate = sessionBean.sessionDate; |
|
| 195 |
- bean.sessionCreateTime = sessionBean.createTime; |
|
| 196 |
- if(bean.photoId>maxId){
|
|
| 197 |
- maxId = bean.photoId; |
|
| 198 |
- } |
|
| 199 |
- photoList.add(bean); |
|
| 200 |
- } |
|
| 201 |
- } |
|
| 202 |
- return true; |
|
| 203 |
- } |
|
| 204 |
- }catch (Exception e){
|
|
| 205 |
- LogHelper.e(TAG,"fetchThumbnailTask exception occurs "+e); |
|
| 206 |
- } |
|
| 207 |
- return false; |
|
| 208 |
- } |
|
| 209 | 106 |
|
| 210 |
- @Override |
|
| 211 |
- protected void onPostFail() {
|
|
| 212 |
- LogHelper.d(TAG,"fetchThumbnailTask onPostFail"); |
|
| 213 |
- super.onPostFail(); |
|
| 214 |
- isLastQueryReturned = true; |
|
| 215 |
- } |
|
| 216 |
- |
|
| 217 |
- @Override |
|
| 218 |
- protected void onPostSuccess() {
|
|
| 219 |
- super.onPostSuccess(); |
|
| 220 |
- isLastQueryReturned = true; |
|
| 221 |
- LogHelper.d(TAG,"fetchThumbnailTask onPostSuccess with photo number = "+photoList.size()); |
|
| 222 |
- for(PhotoBean bean :photoList){
|
|
| 223 |
- new SavePhotoTask(bean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),bean); |
|
| 224 |
- LogHelper.d(TAG,"SavePhotoTask starts "+bean); |
|
| 225 |
- } |
|
| 226 |
- } |
|
| 227 |
- }; |
|
| 228 |
- fetchThumbnailTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.FETCH_THUMBNAIL_URL); |
|
| 229 | 107 |
isLastQueryReturned = false; |
| 230 |
- LogHelper.d(TAG,"fetchThumbnailTask starts"); |
|
| 108 |
+ LogHelper.d(TAG,"fetchPhotoTask starts"); |
|
| 231 | 109 |
} |
| 232 | 110 |
|
| 233 | 111 |
|
| 234 |
- class SavePhotoTask extends AsyncTask<PhotoBean, Integer, Boolean> {
|
|
| 235 |
- |
|
| 236 |
- private PhotoBean photoBean; |
|
| 237 |
- public SavePhotoTask(PhotoBean bean){
|
|
| 238 |
- this.photoBean = bean; |
|
| 239 |
- } |
|
| 240 |
- |
|
| 241 |
- @Override |
|
| 242 |
- protected Boolean doInBackground(PhotoBean... params) {
|
|
| 243 |
- PhotoBean photoBean = params[0]; |
|
| 244 |
- String path = BoxUrlContainer.PHOTO_PATH_PREFIX_URL+photoBean.photoPath; |
|
| 245 |
- if(BuildConfig.isTestMode){
|
|
| 246 |
- path = photoBean.photoPath; |
|
| 247 |
- } |
|
| 248 |
- LogHelper.d(TAG,"SavePhotoTask save photo to phone , photo remote url = "+path); |
|
| 249 |
- FileOutputStream fOut = null; |
|
| 250 |
- HttpURLConnection conn = null; |
|
| 251 |
- InputStream inStream = null; |
|
| 252 |
- try {
|
|
| 253 |
- URL url = new URL(path); |
|
| 254 |
- conn = (HttpURLConnection) url.openConnection(); |
|
| 255 |
- conn.setConnectTimeout(5 * 1000); |
|
| 256 |
- conn.setRequestMethod("GET");
|
|
| 257 |
- inStream = conn.getInputStream(); |
|
| 258 |
- if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
|
|
| 259 |
- String dirPath = Constants.APP_IMAGE_DIR +File.separator+photoBean.sessionId+File.separator+Constants.THUMBNAIL_DIR_NAME; |
|
| 260 |
- File dir = new File(dirPath); |
|
| 261 |
- dir.mkdirs(); |
|
| 262 |
- File file = new File(dir, photoBean.photoName); |
|
| 263 |
- fOut = new FileOutputStream(file); |
|
| 264 |
- byte[] buffer = new byte[2048]; |
|
| 265 |
- int len ; |
|
| 266 |
- while((len=inStream.read(buffer))!=-1){
|
|
| 267 |
- fOut.write(buffer,0,len); |
|
| 268 |
- fOut.flush(); |
|
| 269 |
- } |
|
| 270 |
- fOut.flush(); |
|
| 271 |
- LogHelper.d(TAG,"SavePhotoTask save photo to local path = "+file.getAbsolutePath()+" photo bytes = "+file.length()+"\n"); |
|
| 272 |
- } |
|
| 273 |
- return true; |
|
| 274 |
- } catch (Exception e) {
|
|
| 275 |
- LogHelper.e(TAG,"SavePhotoTask exception occurs "+e); |
|
| 276 |
- } finally {
|
|
| 277 |
- try{
|
|
| 278 |
- inStream.close(); |
|
| 279 |
- conn.disconnect(); |
|
| 280 |
- fOut.close(); |
|
| 281 |
- }catch (Exception e){
|
|
| 282 |
- e.printStackTrace(); |
|
| 283 |
- } |
|
| 284 |
- } |
|
| 285 |
- try{
|
|
| 286 |
- Thread.sleep(2000); |
|
| 287 |
- }catch (Exception e){
|
|
| 288 |
- e.printStackTrace(); |
|
| 289 |
- } |
|
| 290 |
- return false; |
|
| 291 |
- } |
|
| 292 |
- |
|
| 293 |
- @Override |
|
| 294 |
- protected void onPostExecute(Boolean result) {
|
|
| 295 |
- super.onPostExecute(result); |
|
| 296 |
- if (result) {
|
|
| 297 |
- LogHelper.d(TAG,"SavePhotoTask onPostExecute success " + photoBean); |
|
| 298 |
- listener.onSessionPhotoCaptured(photoBean); |
|
| 299 |
- }else{
|
|
| 300 |
- LogHelper.d(TAG,"SavePhotoTask onPostExecute fail and retry "+photoBean); |
|
| 301 |
- new SavePhotoTask(photoBean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),photoBean); |
|
| 302 |
- } |
|
| 303 |
- } |
|
| 304 |
- } |
|
| 305 |
- |
|
| 306 | 112 |
|
| 307 | 113 |
public void endSession(){
|
| 308 | 114 |
isWorking = false; |
@@ -310,36 +116,14 @@ public class SessionInteractor {
|
||
| 310 | 116 |
timer.cancel(); |
| 311 | 117 |
timer = null; |
| 312 | 118 |
} |
| 313 |
- |
|
| 314 |
- cancelTask(sessionEndTask); |
|
| 315 |
- HashMap<String,String> params = new HashMap<>(); |
|
| 316 |
- params.put("lensman",sessionBean.lensmanId);
|
|
| 317 |
- params.put("session",randomSessionId);
|
|
| 318 |
- sessionEndTask = new HttpPostTask(params); |
|
| 319 |
- sessionEndTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_END_URL); |
|
| 320 |
- LogHelper.d(TAG,"sessionEndTask execute "); |
|
| 119 |
+ //TODO |
|
| 321 | 120 |
listener.onSessionEnd(sessionBean.sessionId); |
| 322 | 121 |
} |
| 323 | 122 |
|
| 324 | 123 |
public void deletePhoto(PhotoBean photoBean){
|
| 325 |
- HashMap<String,String> params = new HashMap<>(); |
|
| 326 |
- params.put("lensman",photoBean.lensmanId);
|
|
| 327 |
- params.put("session",photoBean.sessionId);
|
|
| 328 |
- params.put("id",String.valueOf(photoBean.photoId));
|
|
| 329 |
- params.put("name",photoBean.photoName);
|
|
| 330 |
- params.put("path",photoBean.photoPath);
|
|
| 331 |
- HttpPostTask deleteTask = new HttpPostTask(params); |
|
| 332 |
- deleteTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.DELETE_PHOTO_URL); |
|
| 124 |
+ //TODO |
|
| 333 | 125 |
LogHelper.d(TAG,"deletePhoto execute "+photoBean); |
| 334 | 126 |
} |
| 335 | 127 |
|
| 336 |
- private void cancelTask(HttpPostTask task){
|
|
| 337 |
- if(task==null){
|
|
| 338 |
- return; |
|
| 339 |
- } |
|
| 340 |
- if(task.getStatus()== AsyncTask.Status.RUNNING){
|
|
| 341 |
- task.cancel(true); |
|
| 342 |
- } |
|
| 343 |
- } |
|
| 344 | 128 |
|
| 345 | 129 |
} |
@@ -78,12 +78,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
| 78 | 78 |
|
| 79 | 79 |
@Override |
| 80 | 80 |
public void onSessionStartError(String session) {
|
| 81 |
-// if (!isWorking) {
|
|
| 82 |
-// return; |
|
| 83 |
-// } |
|
| 84 | 81 |
sessionView.showToast("session启动失败");
|
| 85 |
-// interactor.startSession(); |
|
| 86 |
-// LogHelper.d(TAG,"onSessionStartError session启动失败,自动重试中"); |
|
| 87 | 82 |
} |
| 88 | 83 |
|
| 89 | 84 |
@Override |
@@ -3,17 +3,12 @@ package ai.pai.lensman.settings; |
||
| 3 | 3 |
import android.content.Intent; |
| 4 | 4 |
import android.os.Bundle; |
| 5 | 5 |
import android.support.annotation.Nullable; |
| 6 |
-import android.view.View; |
|
| 7 |
-import android.widget.EditText; |
|
| 8 |
-import android.widget.Toast; |
|
| 9 | 6 |
|
| 10 | 7 |
import ai.pai.lensman.R; |
| 11 | 8 |
import ai.pai.lensman.activities.AboutUsActivity; |
| 12 | 9 |
import ai.pai.lensman.activities.FeedbackActivity; |
| 13 | 10 |
import ai.pai.lensman.activities.WebViewActivity; |
| 14 | 11 |
import ai.pai.lensman.base.BaseActivity; |
| 15 |
-import ai.pai.lensman.utils.BoxUrlContainer; |
|
| 16 |
-import butterknife.BindView; |
|
| 17 | 12 |
import butterknife.ButterKnife; |
| 18 | 13 |
import butterknife.OnClick; |
| 19 | 14 |
|
@@ -1,26 +0,0 @@ |
||
| 1 |
-package ai.pai.lensman.utils; |
|
| 2 |
- |
|
| 3 |
-public class BoxUrlContainer {
|
|
| 4 |
- |
|
| 5 |
- public static String BOX_IP = "192.168.8.101"; |
|
| 6 |
- |
|
| 7 |
- private static String BASE_URL = "http://" + BOX_IP + ":8002/"; |
|
| 8 |
- |
|
| 9 |
- public static String SESSION_START_URL = BASE_URL + "session_start"; |
|
| 10 |
- |
|
| 11 |
- public static String SESSION_END_URL = BASE_URL + "session_end"; |
|
| 12 |
- |
|
| 13 |
- public static String DELETE_PHOTO_URL = BASE_URL + "delete_photo"; |
|
| 14 |
- |
|
| 15 |
- public static String FETCH_THUMBNAIL_URL = BASE_URL + "fetch_thumbnail"; |
|
| 16 |
- |
|
| 17 |
- public static String PHOTO_PATH_PREFIX_URL = BASE_URL + "static/"; |
|
| 18 |
- |
|
| 19 |
- /** |
|
| 20 |
- * lensman # 摄影师唯一标识 |
|
| 21 |
- * session # Session |
|
| 22 |
- * name # fetch_thumbnail 返回 |
|
| 23 |
- */ |
|
| 24 |
- public static String FETCH_ORIGIN_URL = BASE_URL +"fetch_origin"; |
|
| 25 |
- |
|
| 26 |
-} |
@@ -1,40 +0,0 @@ |
||
| 1 |
-<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
- android:layout_width="match_parent" |
|
| 4 |
- android:layout_height="wrap_content" |
|
| 5 |
- android:orientation="horizontal" |
|
| 6 |
- android:paddingBottom="4dp" |
|
| 7 |
- android:paddingTop="4dp"> |
|
| 8 |
- |
|
| 9 |
- <LinearLayout |
|
| 10 |
- android:layout_width="0dp" |
|
| 11 |
- android:layout_height="wrap_content" |
|
| 12 |
- android:layout_gravity="center_vertical" |
|
| 13 |
- android:orientation="vertical" |
|
| 14 |
- android:layout_weight="1"> |
|
| 15 |
- |
|
| 16 |
- <TextView |
|
| 17 |
- android:id="@+id/tv_device_name" |
|
| 18 |
- android:layout_width="wrap_content" |
|
| 19 |
- android:layout_height="wrap_content" |
|
| 20 |
- android:textColor="@color/dark_grey" |
|
| 21 |
- android:textSize="14sp" /> |
|
| 22 |
- |
|
| 23 |
- <TextView |
|
| 24 |
- android:id="@+id/tv_device_mac" |
|
| 25 |
- android:layout_width="wrap_content" |
|
| 26 |
- android:layout_height="wrap_content" |
|
| 27 |
- android:paddingTop="3dp" |
|
| 28 |
- android:textColor="@color/grey" |
|
| 29 |
- android:textSize="12sp" /> |
|
| 30 |
- </LinearLayout> |
|
| 31 |
- |
|
| 32 |
- <TextView |
|
| 33 |
- android:id="@+id/tv_device_status" |
|
| 34 |
- android:layout_width="wrap_content" |
|
| 35 |
- android:layout_height="wrap_content" |
|
| 36 |
- android:layout_marginRight="12dp" |
|
| 37 |
- android:layout_gravity="center_vertical" |
|
| 38 |
- android:textColor="@color/grey" |
|
| 39 |
- android:textSize="14sp" /> |
|
| 40 |
-</LinearLayout> |